import axios from 'axios' 
import { Message } from 'element-ui'

//创建axios实例
var service = axios.create({
    baseURL: 'http://192.168.0.29:8083/api/', 
    timeout: 5000, 
        headers: {
        'content-type': 'application/x-www-form-urlencoded',
        // "token":'14a1347f412b319b0fef270489f'
    }
}) 

export default {
    
    post(url, param) {
        return new Promise((cback, reject) => {
            service({
                method: 'post',
                url,
                params: param,
            }).then(res => { 
                
                var res_code = res.status.toString();
                if (res_code.charAt(0) == 2) {
                    cback(res);   
                } else {
                    console.log(res, '异常1')
                }
            }).catch(err => {
                if (!err.response) {
                    console.log('请求错误')
                                        
                    Message({
                        showClose: true,
                        message: '请求错误',
                        type: 'error'
                    });
                } else {
                    reject(err.response); 
                    console.log(err.response, '异常2')
                }
            })

        })
    }
} 